package com.breeze.toolkit.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.breeze.toolkit.util.ConstantsUtil;
import com.breeze.toolkit.util.ResUtil;

/**
 * Created by john on 2016/9/1.
 */
public class BaseTitleView extends RelativeLayout {
	private Context mContext;
	private TextView mTitle;
	private View mLeftView;
	private Button mLeft;
	private Button mRight;

	public BaseTitleView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mContext = context;
	}

	protected void onFinishInflate() {
		super.onFinishInflate();

		mLeftView = findViewById(ResUtil.getViewId(mContext, ConstantsUtil.TITLE_LEFT_VIEW_ID_NAME));
		mLeft = (Button) findViewById(ResUtil.getViewId(mContext, ConstantsUtil.TITLE_LEFT_BTN_ID_NAME));
		mRight = (Button) findViewById(ResUtil.getViewId(mContext, ConstantsUtil.TITLE_RIGHT_VIEW_ID_NAME));
		mTitle = (TextView) findViewById(ResUtil.getViewId(mContext, ConstantsUtil.TITLE_TEXT_VIEW_ID_NAME));
	}

	public void show(boolean show) {
		setVisibility(show ? VISIBLE : GONE);
	}

	public void setTitle(Object title) {
		if(title == null){
			show(false);
			return;
		}

		if (title instanceof Integer) {
			mTitle.setText((Integer) title);
		} else if (title instanceof String) {
			mTitle.setText((String) title);
		}
	}

	public Button getLeftBtn() {
		return mLeft;
	}

	public View getLeftView() {
		return mLeftView;
	}

	public Button getRightBtn() {
		return mRight;
	}

	public TextView getTitleView() {
		return mTitle;
	}
}
